﻿Imports Global_Visas_Business_Layer
Imports Global_Visas_Business_Layer.People

Partial Public Class frmAddPhone
    Private _PhoneId As Long
    Private _OldPhoneName As String
    Private _OldPhoneNumber As String

    Public Property PhoneId() As Long
        Get
            Return _PhoneId
        End Get
        Set(ByVal value As Long)
            _PhoneId = value
        End Set
    End Property

    Private Sub frmAddPhone_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles Me.KeyUp

    End Sub

    Private Sub frmAddPhone_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        GeneralTasks.ChangeTheme(Me)
        GeneralTasks.EnumerateandFill(Me.LogicalChildren)
        Me._OldPhoneName = Me.txtPhoneTitle.Text.Trim
        Me._OldPhoneNumber = Me.txtPhoneNumber.Text.Trim
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSave.Click
        If Me.txtPhoneTitle.Text.Trim = String.Empty Then
            CommonFuncs.DisplayMessage("You must enter a name for this phone number!", CommonDialog.CustomDialogIcons.Information, " Enter info ")
            Me.txtPhoneTitle.Focus()
            Exit Sub
        End If

        If Me.txtPhoneNumber.Text.Trim = String.Empty Then
            CommonFuncs.DisplayMessage("You must enter a phone number!", CommonDialog.CustomDialogIcons.Information, " Enter info ")
            Me.txtPhoneNumber.Focus()
            Exit Sub
        End If

        Dim phonenumber As String = Me.txtPhoneNumber.Text
        Dim phoneTitle As String = Me.txtPhoneTitle.Text
        Dim consltantName As String = GlobalCRM.CurrentConName
        Dim candiateId As Long = GlobalCRM.CurrentCandidateID
        Dim phoneType As PhoneTypes = People.PhoneTypes.PhoneOther
        Dim phoneId As Long = Me.PhoneId
        Dim oldPhoneName As String = Me._OldPhoneName
        Dim oldPhoneNumber As String = Me._OldPhoneNumber

        If People.AddPhoneNumber(phonenumber, phoneTitle, consltantName, candiateId, phoneType, 0, phoneId, oldPhoneName, oldPhoneNumber) > 0 Then
            Me.Close()
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnCancel.Click
        Me.Close()
    End Sub
End Class
